﻿using System;
using ITSP.SharePoint.CacheRefresh.Interfaces;

namespace ITSP.SharePoint.CacheRefresh.Entities
{
    /// <summary>
    /// The SharePoint Cache Configuration Item
    /// </summary>
    [Serializable]
    public class SPCacheConfigItem : ICacheConfigItem
    {
        /// <summary>
        /// The SharePoint ListItemId
        /// </summary>
        public int ListItemId { get; set; }

        /// <summary>
        /// The Cache Configuration List Item Unique Id
        /// </summary>
        public string CacheKey { get; set; }

        /// <summary>
        /// The Description of the Cache Configuration Itme
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// The Location of the file that will be used to configure the Cache Dependency Object.
        /// </summary>
        public string CacheDependencyPath { get; set; }

        /// <summary>
        /// The Number of Minutes between each Cache Refresh process.
        /// 0=Never Run.
        /// </summary>
        public int CacheFrequency { get; set; }

        /// <summary>
        /// Is the Cache Enabled for this Cache Configuration Item.
        /// </summary>
        public bool CacheEnabled { get; set; }

        /// <summary>
        /// The Date the Cache Item was created.
        /// </summary>
        private DateTime Created { get; set; }

        /// <summary>
        /// The Date the Cache Item was last modified.
        /// </summary>
        private DateTime Modified { get; set; }

        /// <summary>
        /// Does the Cache Configuraiton Item exist?
        /// </summary>
        public bool Exists
        {
            get { 
                bool bExists = false;
                bExists = this.ListItemId > 0;
                return bExists;
            } 
            set { bool bExists = value; }
        }

        #region Constructors

        /// <summary>
        /// Default Constructor
        /// </summary>
        public SPCacheConfigItem()
        {
            
        }

        /// <summary>
        /// Constructor that creates the SPCacheConfigItem from parameters.
        /// </summary>
        /// <param name="listItemId">SharPoint List Id</param>
        /// <param name="cacheKey">Cache Key</param>
        /// <param name="description">Description</param>
        /// <param name="cacheDependencyPath">File Path</param>
        /// <param name="cacheFrequency">Number of Minutes between each Cache Refresh Operation</param>
        /// <param name="cacheEnabled">Is the Cache to be enabled?</param>
        public SPCacheConfigItem(int listItemId, string cacheKey, string description, string cacheDependencyPath, int cacheFrequency, bool cacheEnabled)
        {
            ListItemId = listItemId;
            CacheKey=cacheKey;
            Description = description;
            CacheDependencyPath = cacheDependencyPath;
            CacheFrequency = cacheFrequency;
            CacheEnabled = cacheEnabled;
            Exists = true;
        }

        #endregion
    }

}
